-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restrict pydantic 2.10.0 #44249
Restrict pydantic 2.10.0 #44249
Conversation
We should have a patch release out this afternoon with a fix for the issues you're encountering :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we need to merge this or not given a 2.10.1 will be out soon
@sydney-runkle Do you plan on yanking the 2.10.0 release? (I don't mind either way, just need to know what we do) If 2.10.0 gets yanked then we don't need to keep this/can revert it, otherwise we probably should keep the exclusion rule |
f770009
to
8e60774
Compare
Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
We're not going to yank v2.10.0, will just release a v2.10.1 patch soon! |
Perhaps you all could test against our |
It would be easier if you have an rc or beta/alpha released in PyPI - because I am not sure if we can trigger the whole test suite against Github-installed version. Can it be done @sydney-runkle ? |
You can try with |
It might be that we expect version in our CI for that, so I am not sure if it's going to work . I can try, but I have a feeling it will fail in one of the steps. |
yeah i think it might fail at constraints ? |
Trying it here @sydney-runkle #44260 |
Yeah... some tests are already failing here as I suspected. But those are auxiliary ones, maybe the main part of the tests that actually failed before will be ok:
|
We're going to release 2.10.1 any minute now. We got a report today of an issue happening on Python <3.10. The a.py from logging import Logger
class Base:
_log: 'Logger | None' b.py from a import Base
from pydantic import BaseModel
class Model(BaseModel, Base):
pass Evalutating the annotation for What's probably best is to make sure you're using the old syntax for every class that is going to be used in the context of a Pydantic model. |
Just released v2.10.1 with fixes for the issues you folks reported :) |
As discussed in pydantic/pydantic#10924 (comment) - I think this change is breaking far too much of an existing code base and you are facing the reality that this will cause even more people to limit their Pydantic version to < 2 (it looks like the |
Since the release of 2.10, we only had one report (pydantic/pydantic#10924) related to evaluation of forward annotations.
We are aware of that, it is, in some cases, extremely challenging for us to make changes/cleanups, especially because in the field of forward annotations evaluation. The standard library utilities are far from perfect, so we had to implement our own logic to support edge cases that unfortunately led to a messy implementation, accepting invalid annotations to evaluate (this can be dangerous as names in forward annotations could resolve to the wrong type) 1.
Honestly, this requires a one line change on your end: airflow/airflow/utils/log/logging_mixin.py Lines 68 to 78 in f33166a
Your usage of type annotations is inconsistent here, as you are mixing the new union syntax with
The "fix" is not actually a fix, but a complete refactor of our forward annotations evaluation. It's unfortunately not possible for us to "revert" it. The current implementation is vastly more accurate, and as I said above will avoid dangerous issues when forward annotations are silently not resolved to the correct type. If we do get more reports, depending on their validity, we will then consider tweaking the current logic. Footnotes |
For instance: langchain-ai/langchain-google#610 is an example of a forward annotation evaluation that resolved to the wrong type in <2.10 (I'm in the process of writing up what's happening). |
Indeed this is not great. We have all the codebase updated to the new style type annotation. (
We use |
Sure. It is indeed up to you. We are pretty well protected - we have "constraint mechanism" and we can restric airlfow 2.10.4 - and we are rather happy to adjust future versions of airflow, I was just merely suggesting that this change might have more consequences for you - so It was more of a friendly advice than complaint. But yes - I agree my assesment might be wrong.
Yes - but to be perfectly honest it's because of Pydantic. We have a rule in our pre-commit that enforces using new style type annotations. Because of inability of pydantic to handle it, we specifically converted our Pydantic classes to not use https://github.com/apache/airflow/blob/main/pyproject.toml#L326 So our "inconistent use" is exclusively because of Pydantic. And our use is perfectly fine according to current state of type annotations - both style of annotations can be inter-mixed and So technically speaking it's because of Pydantic we are inconsistent. And I am not complaining and not trying to heat it up, I am just stating the fact - explaining that well, it's Pydantic who is the root cause of that inconsistency, not Airflow. So really - @Viicos - please treat it as a friendly advice, that maybe it's a good idea to consider supporting that case. While we will handle it ourselves (luckily our constraint mechanism we introduce many years ago and educate our users to use them will prevent a lot of our users from being affected). It's really a maintainer-to-maintainer friendly suggestion that this might hit you back. |
Yes sorry what I meant is precisely on the But as you mentioned, nothing related to this should be an issue if the Turns out, the backport was added in 7d5f2ba, and the user is still on
Sorry if I did not understand it that way. I think we both know how annoying unexpected breaking changes can be. In this case, the intent was to fix actual invalid cases (such as this one) and I would find it very unfortunate to consider Pydantic in the same state as other well established libraries (e.g. Regarding the "inconsistent use" we are talking about, as I answered at the top of this comment, it was in fact due to the reporting user not using the latest airfow version which included the evaluation backport.
Pydantic is not really to blame here. There are some PEP 563 use cases that are theoretically impossible to support (e.g. referencing locals in a function) (and we had/will have to wait for PEP 649 to resolve most of these cases). And compared to the other dataclass-like libraries performing validation, I'm not afraid to say Pydantic is by far the most accurate when it comes to handling forward annotations, including the Thanks again, I'll close the original issue by suggesting upgrading to the latest airflow version. Please let us know if you encounter more issues with 2.10.1. |
Sidenote: Prior to the final 2.10 release, I was looking at libraries making extensive use of Pydantic. I tested on some, but wasn't aware airflow was using it, along with |
Great to hear! Yes the usage in airflow started small but it's becoming more and more central in our datamodel.
Thanks for the details 👍 |
Yes. thanks for all details. Again, it was not blaming or complaint (and I know how difficult it is to pass emotions and intents via GitHub issues. And yes - i know, and quote https://xkcd.com/1172/ more often than not. Also what gets handy in such case is https://www.hyrumslaw.com/ (which BTW also has the reference to the XKCD in question) :) . Now all is clear. I've also learned about FYI @Viicos - that one was added only in main and is going to be added as a requirement in Airflow 3.0. But as far as I understand, just installing it should generally solve the problem that the use had with databricks-dbt. So @pierrejeambrun -> maybe this is the right fix that we should add to 2.10.4 - simply add |
@pierrejeambrun Created #44294 -> I noticed that the |
Sounds great thanks Jarek. Yes indeed when I first introduced it, I really didn’t know it would be all that important and have to be cherry picked. It was really just to fix issues I was facing with initial development of the FastAPI API. Now looking back, indeed a PR of its own would have been nice 😄 |
Recent pydantic 2.10.0 release causing failures in CI.
It seems there is ticket already opened here. pydantic/pydantic#10910
Failing tests in CI https://github.com/apache/airflow/actions/runs/11954326679/job/33324739597#step:7:12365
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rst
or{issue_number}.significant.rst
, in newsfragments.